home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / Dialectic 1.1 Source / Dialectic ƒ / MSG Shell ƒ / msg menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  4.4 KB  |  211 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg menus.c
  4.  
  5. Purpose:    This module handles menu selections.
  6.  
  7.  
  8.  
  9. Dialectic -=- dialect text conversion extraordinare
  10. Copyright ©1994, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg graphics.h"
  30. #include "msg menus.h"
  31. #include "msg help.h"
  32. #include "msg prefs.h"
  33. #include "msg environment.h"
  34. #include "program globals.h"
  35. #include "dialectic.h"
  36. #include "dialectic dispatch.h"
  37.  
  38. MenuHandle        gAppleMenu;
  39. MenuHandle        gFileMenu;
  40. MenuHandle        gEditMenu;
  41. MenuHandle        gOptionsMenu;
  42. MenuHandle        gHelpMenu;
  43. MenuHandle        gDialectMenu;
  44.  
  45. void AdjustMenus(void)
  46. {
  47.     WindowPeek        theWindow;
  48.     int                kind;
  49.     int                i;
  50.     unsigned char    iter;
  51.     
  52.     if (!gInProgress)
  53.     {
  54.         EnableItem(gAppleMenu, aboutItem);
  55.         EnableItem(gAppleMenu, aboutMSGItem);
  56.         EnableItem(gAppleMenu, helpItem);
  57.         EnableItem(gFileMenu, 0);
  58.         EnableItem(gEditMenu, 0);
  59.         EnableItem(gOptionsMenu, 0);
  60.         EnableItem(gDialectMenu, 0);
  61.     }
  62.     else
  63.     {
  64.         DisableItem(gAppleMenu, aboutItem);
  65.         DisableItem(gAppleMenu, aboutMSGItem);
  66.         DisableItem(gAppleMenu, helpItem);
  67.         DisableItem(gFileMenu, 0);
  68.         DisableItem(gEditMenu, 0);
  69.         DisableItem(gOptionsMenu, 0);
  70.         DisableItem(gDialectMenu, 0);
  71.     }
  72.     
  73.     theWindow = (WindowPeek)FrontWindow();
  74.     kind = theWindow ? theWindow->windowKind : 0;
  75.     
  76.     if(kind < 0)
  77.         EnableItem(gEditMenu, 0);
  78.     else
  79.         DisableItem(gEditMenu, 0);
  80.     
  81.     if(theWindow)
  82.         EnableItem(gFileMenu, closeItem);
  83.     else
  84.         DisableItem(gFileMenu, closeItem);
  85.     
  86.     CheckItem(gOptionsMenu, showSaveItem, gShowSaveDialog);
  87.     CheckItem(gOptionsMenu, addSuffixItem, gAddSuffix);
  88.     CheckItem(gOptionsMenu, showProgressItem, gShowProgress);
  89.     CheckItem(gOptionsMenu, rtfItem, gUseRTF);
  90.     SetSuffixMenuItem(gOptionsMenu, addSuffixItem);
  91.     for (iter=0; iter<CountMItems(gDialectMenu); iter++)
  92.         CheckItem(gDialectMenu, iter+1, (iter==gWhichDialect));
  93. }
  94.  
  95. void HandleMenu(long mSelect)
  96. {
  97.     int            menuID = HiWord(mSelect);
  98.     int            menuItem = LoWord(mSelect);
  99.     
  100.     switch (menuID)
  101.     {
  102.         case appleMenu:
  103.             HandleAppleMenu(menuItem);
  104.             break;
  105.         case fileMenu:
  106.             HandleFileMenu(menuItem);
  107.             break;    
  108.         case editMenu:
  109.             HandleEditMenu(menuItem);
  110.             break;
  111.         case optionsMenu:
  112.             HandleOptionsMenu(menuItem);
  113.             break;
  114.         case helpMenu:
  115.             HandleHelpMenu(menuItem);
  116.             break;
  117.         case dialectMenu:
  118.             HandleDialectMenu(menuItem);
  119.             break;
  120.       }
  121. }
  122.  
  123. void HandleAppleMenu(int menuItem)
  124. {
  125.     GrafPtr        savePort;
  126.     Str255        name;
  127.     
  128.     if(menuItem == 1)
  129.         OpenTheWindow(kAbout);
  130.     if (menuItem == 2)
  131.         OpenTheWindow(kAboutMSG);
  132.     else if(menuItem > 4)
  133.     {
  134.         GetPort(&savePort);
  135.         GetItem(gAppleMenu, menuItem, name);
  136.         OpenDeskAcc(name);
  137.         SetPort(savePort);
  138.     }
  139. }
  140.  
  141. void HandleFileMenu(int menuItem)
  142. {
  143.     WindowPtr            theWindow;
  144.     int                    i;
  145.     Boolean                gotone;
  146.     
  147.     switch (menuItem)
  148.     {
  149.         case openItem:
  150.             NewConvert();
  151.             break;
  152.         case closeItem:
  153.             theWindow=FrontWindow();
  154.             gotone=FALSE;
  155.             for (i=0; (i<NUM_WINDOWS) && (!gotone); i++)
  156.                 gotone=(theWindow==gTheWindow[i]);
  157.                 
  158.             if (gotone)
  159.                 CloseTheWindow(i-1);
  160.             else
  161.                 DisposeWindow(theWindow);
  162.             
  163.             AdjustMenus();
  164.             break;
  165.         case quitItem:
  166.             gDone = TRUE;
  167.             break;
  168.     }
  169. }
  170.  
  171. void HandleEditMenu(int menuItem)
  172. {
  173.     SystemEdit(menuItem - 1);
  174. }
  175.  
  176. void HandleHelpMenu(int menuItem)
  177. {
  178.     gWhichHelp=menuItem;
  179.     UpdateHelpWindow();
  180. }
  181.  
  182. void HandleOptionsMenu(int menuItem)
  183. {
  184.     switch (menuItem)
  185.     {
  186.         case showSaveItem:
  187.             gShowSaveDialog=!gShowSaveDialog;
  188.             SaveThePrefs();
  189.             break;
  190.         case addSuffixItem:
  191.             gAddSuffix=!gAddSuffix;
  192.             SaveThePrefs();
  193.             break;
  194.         case showProgressItem:
  195.             gShowProgress=!gShowProgress;
  196.             SaveThePrefs();
  197.             break;
  198.         case rtfItem:
  199.             gUseRTF=!gUseRTF;
  200.             SaveThePrefs();
  201.             break;
  202.     }
  203. }
  204.  
  205. void HandleDialectMenu(int menuItem)
  206. {
  207.     gWhichDialect=menuItem-1;
  208.     SaveThePrefs();
  209.     AdjustMenus();
  210. }
  211.